import requests
import re
from requests_toolbelt import MultipartEncoder
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:ECDHE:!COMPLEMENTOFDEFAULT"
def report(Pass, Name):

    headers = {
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "accept-encoding": "gzip, deflate, br",
        "accept-language": "zh-CN,zh;q=0.9",
        "sec-fetch-dest": "document",
        "sec-fetch-mode": "navigate",
        "sec-fetch-site": "none",
        "upgrade-insecure-requests": "1",
        "user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"
    }
 
    session = requests.session()

    res = session.post("http://app.zafu.edu.cn/app/user/login.jhtm", params = {"enPassword": Pass, "userName": Name}, headers = headers)
    token = re.findall("\"token\":\"(.*)\"", res.text)
    params = {
        "id" : "194",
        "token" : token
    }

    res = session.post("http://app.zafu.edu.cn/app/app/getopenappinfo.jhtm", headers = headers, params = params)

    url = re.findall("\"url\":\"(.*)\",\"ss", res.text)[0]

    res = session.get(url, headers = headers, allow_redirects = False)


    url = res.headers["Location"]


    res = session.get(url, headers = headers, allow_redirects = False)

    url = res.headers["Location"]

    #print(url)

    token = re.findall("token=(.*)&_t", url)[0]


        
    m = MultipartEncoder(
    fields={'stryqdj': '''

    {"id":8611199,"bjbh":"201805","bjmc":"计算机181","djsj":1618670211000,"fhcfd":"","jg":"浙江省","twqk":"1","twds":36.50,"qq":null,
    "qtxybbqk":null,"qx":"1","qxdz":"1","sfjk":"1","sfyfzfl":"1","sfzbfzfl":"0","sj":"","tbrq":"2021-04-17","xh":"","xm":"",
    "yfzflsj":"","yqzk":"1","ywmqjcs":"1","zbfzflsj":"","jrjkzk":"2","jrjkzkrs":null,"jrjkzkgx":null,"kszk":"2","healthCodePic":"",
     "healthCodeUrl":"","healthCodeColor":"1","rjqk":"0","fxfs":1,"fxfsbz":"","fxrq":"2020-05-05","dzsj":"2020-05-05 07:45","ymjzyzfy":false,"ymjzqk":"4","todaySubmitted":1}

      ''',
      'file': 'undefined'})

    

    res = session.post("https://appui.zafu.edu.cn/vapp/yqdj/submit.jhtm?token=" + token, data = m, headers = {'Content-Type': m.content_type})



    print(res.text)

def groupreport():


    users = {
        0 : {"user" : "201805120114", "passkey" : "aa123456789."},
        1 : {"user" : "201905020105", "passkey" : "20010216xby"},
        2 : {"user" : "201602080334", "passkey" : "123456"},
      
        3 : {"user" : "201905020105", "passkey" : "20010216xby"},
        4 : {"user" : "201805120114", "passkey" : "aa123456789."},
        5 : {"user" : "201602080334", "passkey" : "123456"},
    }

    for key in users:
        user = users[key]
        report(user["passkey"], user["user"])


if __name__ == '__main__':

    groupreport()
  
            
        


